package com.cn.demo4.dao.impl;

import com.cn.demo4.dao.NavTypeDao;
import com.cn.demo4.model.NavTypeModel;
import com.cn.demo4.util.GetSqlSession;
import com.cn.demo4.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NavTypeDaoImpl implements NavTypeDao {
    @Override
    public List<NavTypeModel> findAll() {
//        String sql = "select * from nav_type order by id desc";
//        ResultSet resultSet = JDBC.select(sql);
//        return getData(resultSet);
        return GetSqlSession.getSqlSession().selectList("com.cn.demo4.dao.NavTypeDao.findAll");
    }
    private List<NavTypeModel> getData(ResultSet resultSet) {
        List<NavTypeModel> list = new ArrayList<>();
        try{
            while(resultSet.next()){
                NavTypeModel navTypeModel = new NavTypeModel();
                navTypeModel.setName(resultSet.getString("name"));
                navTypeModel.setId(resultSet.getInt("id"));
                navTypeModel.setStatus(resultSet.getInt("status"));
                navTypeModel.setCreateTime(resultSet.getString("create_time"));
                navTypeModel.setUpdateTime(resultSet.getString("update_time"));
                list.add(navTypeModel);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
